﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace AtlasWebApp
{
    /// <summary>
    /// Summary description for DisplayFlag1
    /// </summary>
    public class DisplayFlag1 : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            int flagId = Int32.Parse(context.Request.QueryString["flagId"]); 
            using (AtlasEntities entities = new AtlasEntities())
            {
                Flag flag = entities.Flags.FirstOrDefault(f => f.FlagId == flagId);

                if (flag != null)
                {
                    context.Response.ContentType = "image/png";
                    context.Response.OutputStream.Write(flag.FlagContent, 0, flag.FlagContent.Length);                    
                }
            }                    
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}